# 构建阶段
FROM node:18-alpine AS builder

# 设置工作目录
WORKDIR /app

# 安装pnpm
RUN npm install -g pnpm

# 复制package.json和pnpm-lock.yaml
COPY package.json pnpm-lock.yaml ./

# 安装项目依赖
RUN pnpm install

# 复制项目文件
COPY . .

# 构建项目
RUN pnpm run build

# 生产阶段
FROM node:18-alpine AS runner

WORKDIR /app

# 安装生产环境需要的包
RUN npm install -g pnpm

# 从构建阶段复制必要文件
COPY --from=builder /app/package.json ./
COPY --from=builder /app/pnpm-lock.yaml ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public

# 只安装生产环境依赖
RUN pnpm install

# 设置环境变量
ENV NODE_ENV=production
ENV PORT=80

EXPOSE 80

# 启动Next.js应用
CMD ["pnpm", "start"]
